package com.paopao.employee.controller;

import com.paopao.domain.EmployeeBean;
import com.paopao.domain.R;
import com.paopao.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("api/v1/employee")
public class EmployeeComtroller {

    @Autowired
    private EmployeeService employeeService;

    @PostMapping
    public R addEmployee(@RequestBody EmployeeBean employeeBean){

        return employeeService.addEmployee(employeeBean);
    }

    @DeleteMapping("{id:\\d+}")
    public R deleteEmployee(@PathVariable("id")Integer id){

        return employeeService.deleteEmployee(id);
    }

    @PutMapping
    public R editEmployee(@RequestBody EmployeeBean employeeBean){

        return employeeService.editEmployee(employeeBean);
    }

    @GetMapping("{id:\\d+}")
    public R getEmployee(@PathVariable("id")Integer id){

        return employeeService.selectEmployee(id);
    }

    @PostMapping("aa")
    @ResponseBody()
    public R getItemInfoList(@RequestParam(value = "pageNum", required = false) Integer pageNum,
                             @RequestParam(value = "pageSize", required = false, defaultValue = "25") Integer pageSize){
        EmployeeBean employeeBean = new EmployeeBean();
        employeeBean.setAge(1);
        return employeeService.selectEmployeeList(pageNum, pageSize, employeeBean);
    }
}
